package com.hcrazy.manchester.app.services;

import com.hcrazy.manchester.app.jdbc.LiveSimpleDAO;
import com.hcrazy.manchester.app.pojo.ErrorMsg;
import com.hcrazy.manchester.app.pojo.LiveSimple;
import com.hcrazy.manchester.app.pojo.PageModel;
import com.hcrazy.manchester.app.utils.Constant;

public class LiveSimpleService {

	private LiveSimpleDAO liveSimpleDAO;
	
	public LiveSimpleDAO getLiveSimpleDAO() {
		return liveSimpleDAO;
	}

	public void setLiveSimpleDAO(LiveSimpleDAO liveSimpleDAO) {
		this.liveSimpleDAO = liveSimpleDAO;
	}

	public ErrorMsg addOrUpdateLiveSimple(LiveSimple simple) throws Exception{
		ErrorMsg msg = new ErrorMsg();
		msg.setCode(Constant.SUCCESS);//success
		if(simple.getInfoId()>0){
			simple.setPraiseCount(simple.getPraiseCount() + simple.getPraiseBaseCount());
			simple.setCommentCount(simple.getCommentCount() + simple.getCommentBaseCount());
			
			
			liveSimpleDAO.updateLiveSimple(simple);
		}else{
			if(null != simple && simple.getPraiseBaseCount() > 0){
				simple.setPraiseCount(simple.getPraiseBaseCount());
			}
			if(null != simple && simple.getCommentBaseCount() > 0){
				simple.setCommentCount(simple.getCommentBaseCount());
			}
			liveSimpleDAO.addLiveSimple(simple);
		}
		
		return msg;
	}
	
	public PageModel getSimpleInfos(PageModel model,String search,int sortId) throws Exception{
		return liveSimpleDAO.getPagedInfos(model, search, sortId);
	}
	
	public LiveSimple getInfoById(int infoId) throws Exception{
		return liveSimpleDAO.getById(infoId);
	}
	
	public void delLiveSimple(int infoId) throws Exception{
		liveSimpleDAO.delLiveSimple(infoId);
	}
}
